package com.longlong.controller.adminApi;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.longlong.entity.RegistrationRacetrack;
import com.longlong.mapper.RegistrationRacetrackMapper;
import com.longlong.service.impl.RegistrationRaceTrackServiceImpl;
import com.longlong.vo.PaginationVo;
import com.longlong.vo.RegistrationFormVo;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@Api(value = "后台比赛系统接口")
@RequestMapping("/registration")
public class registration {
    @Autowired
    private RegistrationRacetrackMapper registrationRacetrackMapper;

    @Autowired
    private RegistrationRaceTrackServiceImpl registrationRaceTrackService;



    /**
     * 获取列表总数
     * @return
     */
    @PostMapping("/getRegistrationRaceTrackCounts")
    public Integer getRegistrationRaceTrackCounts(){
        return registrationRacetrackMapper.selectList(null).size();
    }

    /**
     * 分页查询
     * @return
     */
    @PostMapping("/getRegistrationRaceTrackList")
    public Object getRegistrationRaceTrackList(@RequestBody PaginationVo paginationVo){
        Page<RegistrationRacetrack> page = new Page<>(paginationVo.getPage(),paginationVo.getSize());
        return registrationRacetrackMapper.selectPage(page,null);
    }
    
    /**
     * 根据id删除信息
     * @param id
     * @return
     */
    @GetMapping("/registrationDeleteById")
    public Integer registrationDeleteById( Integer id){
        return registrationRacetrackMapper.deleteById(id);
    }

    /**
     * 添加赛道信息
     * @param registrationForm
     * @return
     */
    @PostMapping("/registrationInsert")
    public Integer registrationInsert(@RequestBody RegistrationFormVo registrationForm){
        RegistrationRacetrack registrationRacetrack = new RegistrationRacetrack();
        registrationRacetrack.setRaceTrackName(registrationForm.getRaceTrackName());
        registrationRacetrack.setRaceTrackDescribe(registrationForm.getRaceTrackDescribe());
        return  registrationRacetrackMapper.insert(registrationRacetrack);
    }

    /**
     * 修改赛道信息
     * @param registrationForm
     * @return
     */
    @PostMapping("/registrationUpdate")
    public Integer registrationUpdate(@RequestBody RegistrationFormVo registrationForm){
        RegistrationRacetrack registrationRacetrack = new RegistrationRacetrack();
        registrationRacetrack.setId(registrationForm.getId());
        registrationRacetrack.setRaceTrackName(registrationForm.getRaceTrackName());
        registrationRacetrack.setRaceTrackDescribe(registrationForm.getRaceTrackDescribe());
        return registrationRacetrackMapper.updateById(registrationRacetrack);
    }

}















